﻿using System;
using Gtk;
using Cairo;
namespace GtkCairo
{
    #region 绘图测试

    //class SharpApp :Window
    //{
    //    public SharpApp() : base("Donut")
    //    {
    //        SetDefaultSize(350, 250);
    //        SetPosition(WindowPosition.Center);
    //        DeleteEvent += delegate { Application.Quit(); };

    //        DrawingArea darea = new DrawingArea();
    //        darea.Drawn += OnExpose;
    //        //darea.ExposeEvent += OnExpose;
    //        //darea.Events += OnExpose;
    //        Add(darea);

    //        ShowAll();
    //    }

    //    void OnExpose(object sender, DrawnArgs args)
    //    //void OnExpose(object sender, ExposeEventArgs args)
    //    {
    //        DrawingArea area = (DrawingArea)sender;
    //        //Cairo.Context cr = Gdk.CairoHelper.Create(area.GdkWindow);
    //        Context cr = args.Cr;
    //        cr.LineWidth = 0.5;

    //        int width, height;
    //        width = Allocation.Width;
    //        height = Allocation.Height;

    //        cr.Translate(width / 2, height / 2);
    //        cr.Arc(0, 0, 120, 0, 2 * Math.PI);
    //        cr.Stroke();

    //        cr.Save();

    //        for (int i = 0; i < 36; i++)
    //        {
    //            cr.Rotate(i * Math.PI / 36);
    //            cr.Scale(0.3, 1);
    //            cr.Arc(0, 0, 120, 0, 2 * Math.PI);
    //            cr.Restore();
    //            cr.Stroke();
    //            cr.Save();
    //        }

    //        ((IDisposable)cr.Target).Dispose();
    //        ((IDisposable)cr).Dispose();
    //    }


    //    public static void Main()
    //    {
    //        Application.Init();
    //        new SharpApp();
    //        Application.Run();
    //    }
    //}
    #endregion
    #region 多控件+绘图
    class SharpApp : Window
    {

        DrawingArea darea;
        Gdk.Color col;

        
        public SharpApp() : base("ToggleButtons")
        {
            col = new Gdk.Color(0, 0, 0);
            
            SetDefaultSize(350, 240);
            SetPosition(WindowPosition.Center);
            BorderWidth = 7;
            DeleteEvent += delegate { Application.Quit(); };

            ToggleButton red = new ToggleButton("Red");
            red.SetSizeRequest(80, 35);
            red.Clicked += OnRed;

            ToggleButton green = new ToggleButton("Green");
            green.SetSizeRequest(80, 35);
            green.Clicked += OnGreen;

            ToggleButton blue = new ToggleButton("Blue");
            blue.SetSizeRequest(80, 35);
            blue.Clicked += OnBlue;

            darea = new DrawingArea();
            darea.SetSizeRequest(150, 150);
            darea.ModifyBg(StateType.Normal, col);
            //darea.di
            Fixed fix = new Fixed();
            fix.Put(red, 30, 30);
            fix.Put(green, 30, 80);
            fix.Put(blue, 30, 130);
            fix.Put(darea, 150, 30);

            Add(fix);

            ShowAll();
        }

        void OnRed(object sender, EventArgs args)
        {
            ToggleButton tb = (ToggleButton)sender;

            if (tb.Active)
            {
                col.Red = 65535;
            }
            else
            {
                col.Red = 0;
            }

            darea.ModifyBg(StateType.Normal, col);
        }

        void OnGreen(object sender, EventArgs args)
        {
            ToggleButton tb = (ToggleButton)sender;

            if (tb.Active)
            {
                col.Green = 65535;
            }
            else
            {
                col.Green = 0;
            }

            darea.ModifyBg(StateType.Normal, col);
        }

        void OnBlue(object sender, EventArgs args)
        {
            ToggleButton tb = (ToggleButton)sender;

            if (tb.Active)
            {
                col.Blue = 65535;
            }
            else
            {
                col.Blue = 0;
            }

            darea.ModifyBg(StateType.Normal, col);
        }

        public static void Main()
        {
            Application.Init();
            new SharpApp();
            Application.Run();
        }
    }
    #endregion
}
